/**
* @author:kellen
* @contact:xiekellen@hotmail.com
* @company:achivo-gz
* @created on:
* @modified on:
*/

package com.sasis.dao.ibatis;

import java.util.List;

import com.sasis.dao.ibatis.BaseDaoiBATIS;
import com.sasis.model.VipServiceCabin;
import com.sasis.dao.VipServiceCabinDao;

import org.springframework.orm.ObjectRetrievalFailureException;

public class VipServiceCabinDaoiBatis extends BaseDaoiBATIS implements VipServiceCabinDao {

    /**
     * @see com.sasis.dao.VipServiceCabinDao#getVipServiceCabins(com.sasis.model.VipServiceCabin)
     */
    public List getVipServiceCabins(final VipServiceCabin vipServiceCabin) {
          return getSqlMapClientTemplate().queryForList("getVipServiceCabins", vipServiceCabin);
    }

    /**
     * @see com.sasis.dao.VipServiceCabinDao#getVipServiceCabin(Integer id)
     */
    public VipServiceCabin getVipServiceCabin(Integer id) {
        VipServiceCabin vipServiceCabin = (VipServiceCabin) getSqlMapClientTemplate().queryForObject("getVipServiceCabin", id);

//        if (vipServiceCabin == null) {
//            throw new ObjectRetrievalFailureException(VipServiceCabin.class, id);
//        }

        return vipServiceCabin;
    }

    /**
     * @see com.sasis.dao.VipServiceCabinDao#saveVipServiceCabin(VipServiceCabin vipServiceCabin)
     */    
    public int saveVipServiceCabin(final VipServiceCabin vipServiceCabin) {
        Integer id = vipServiceCabin.getId();
        // check for new record
        if (id == null) {
            id = (Integer) getSqlMapClientTemplate().insert("addVipServiceCabin", vipServiceCabin);
        } else {
            getSqlMapClientTemplate().update("updateVipServiceCabin", vipServiceCabin);
        }
        if( id == null ) {
            throw new ObjectRetrievalFailureException(VipServiceCabin.class, id);
        }
        return id.intValue();
    }

    /**
     * @see com.sasis.dao.VipServiceCabinDao#removeVipServiceCabin(Integer id)
     */
    public void removeVipServiceCabin(VipServiceCabin vipServiceCabin) {
        getSqlMapClientTemplate().update("deleteVipServiceCabin",  vipServiceCabin);
    }
}
